package com.taritari.journal.controller;

import com.taritari.journal.entity.dto.JournalInfoDto;
import com.taritari.journal.entity.dto.UserLikeDto;
import com.taritari.journal.entity.po.TreeHole;
import com.taritari.journal.entity.vo.TreeHoldDetailVo;
import com.taritari.journal.entity.vo.TreeHoldVo;
import com.taritari.journal.services.TreeHoleService;
import com.taritari.journal.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author taritari
 * @date 2024-01-18 16:23
 * @description 树洞
 */
@RestController
@Slf4j
@Tag(name = "树洞", description = "树洞")
@RequestMapping("/treeHole")
public class TreeHoleController {
    @Autowired
    private TreeHoleService treeHoleService;
    @GetMapping("/roam")
    @Operation(summary = "开始漫游", description = "开始漫游and下一个")
    public Result roam(@RequestParam String userId) {

        TreeHoldDetailVo treeHoldDetailVo = treeHoleService.treeRoam(userId);
        return Result.success(treeHoldDetailVo);
    }
    @GetMapping("/isLike")
    @Operation(summary = "用户是否点赞", description = "用户是否点赞")
    public Result isLike(@RequestParam int userId,@RequestParam int treeHoleId) {
        int res = treeHoleService.userIsLike(userId , treeHoleId);
        return Result.success(res);
    }
    @PostMapping("/userLike")
    @Operation(summary = "用户点击喜欢", description = "用户点击喜欢")
    public Result userLike(@RequestBody UserLikeDto userLikeDto){
        treeHoleService.userLikeMq(userLikeDto);
        return Result.success();
    }
    @PostMapping("/add")
    @Operation(summary = "投递树洞", description = "投递树洞")
    public Result deliverHold(@RequestBody TreeHole treeHole){
        int res = treeHoleService.deliverTreeHold(treeHole);
        return Result.success(res);
    }
    @GetMapping("/news")
    @Operation(summary = "获取最新的十篇树洞", description = "获取最新的十篇树洞")
    public Result getNew(){
        List<TreeHoldVo> treeHoldVos = treeHoleService.newTreeHold();
        return Result.success(treeHoldVos);
    }
    @GetMapping("/likes")
    @Operation(summary = "获取最多喜欢的十篇树洞", description = "获取最多喜欢的十篇树洞")
    public Result getlikes(){
        List<TreeHoldVo> treeHoldVos = treeHoleService.likeDesc();
        return Result.success(treeHoldVos);
    }
    @GetMapping("/userLikes")
    @Operation(summary = "获取用户喜欢的树洞", description = "获取用户喜欢的树洞")
    public Result getUserLikes(@RequestParam int userId,@RequestParam int page,@RequestParam(defaultValue = "5") int pageSize){
        List<TreeHoldVo> treeHoldVos = treeHoleService.userLikes(userId,page,pageSize);
        return Result.success(treeHoldVos);
    }

    @GetMapping("/getUserList")
    @Operation(summary = "获取用户投递的树洞文章列表", description = "获取用户投递的树洞文章列表")
    public Result getUserList(@RequestParam int userId,@RequestParam int page,@RequestParam(defaultValue = "5") int pageSize){
        List<TreeHoldVo> treeHoldVos = treeHoleService.getUserTreeHolds(userId, page, pageSize);
        return Result.success(treeHoldVos);
    }
    @GetMapping("/treeHoldById")
    @Operation(summary = "通过id获取树洞内容", description = "通过id获取树洞内容")
    public Result treeHoldById(@RequestParam int treeHoldId){
        TreeHole treeHoldById = treeHoleService.getTreeHoldById(treeHoldId);
        return Result.success(treeHoldById);
    }
    @GetMapping("/treeHoldCar")
    @Operation(summary = "用户点击树洞卡片返回详情", description = "用户点击树洞卡片返回详情")
    public Result treeHoldCar(@RequestParam int treeHoldId){
        TreeHoldDetailVo treeHoldDetailVo = treeHoleService.treeHoldCarClick(treeHoldId);
        return Result.success(treeHoldDetailVo);
    }
}
